/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.geergenbein.azw.dao.transcription;

import javax.persistence.EntityManager;
import org.geergenbein.azw.model.transcription.TranscriptionSystem;
import org.geergenbein.azw.model.transcription.UntonedCodePoint;
import org.geergenbein.azw.model.transcription.UntonedTranscription;
import org.geergenbein.dao.GenericHibernateDAO;

/**
 *
 * @author andrew
 */
public class UntonedTranscriptionDAOHibernate extends GenericHibernateDAO<UntonedTranscription, Long> {
    
    public UntonedTranscriptionDAOHibernate(EntityManager em) {
        super(em);
    }
    
    public UntonedTranscription find(TranscriptionSystem transcriptionSystem,
            UntonedCodePoint untonedCodePoint) 
    {
        return (UntonedTranscription) getSession().
                getNamedQuery("findUntonedTranscription").
                setParameter("transcriptionSystem", transcriptionSystem).
                setParameter("untonedCodePoint", untonedCodePoint).
                uniqueResult();
    }
    
    // persistOrUpdate
    // factory/create
    public UntonedTranscription loadOrPersist(UntonedCodePoint untonedCodePoint,
            TranscriptionSystem transcriptionSystem, String transcription) 
    {
        UntonedTranscription ut = null;
        if ((ut = find(transcriptionSystem, untonedCodePoint)) == null) {
            ut = new UntonedTranscription(untonedCodePoint, transcriptionSystem, 
                    transcription);
            makePersistent(ut);
            log.debug("Persisted UntonedTranscription: " + ut);
        } else {
            // update???
            log.debug("Found UntonedTranscription: " + ut);
        }
        return ut;
    }
    
}
